﻿-- =============================================
-- Script Template
-- =============================================


CREATE PROCEDURE P_TrendChart_7CL_HMFB --七彩乐综合号码分布图

AS

set nocount on

Create table #LotteryNumberList7CL(id int identity(1,1),Isuse varchar(20),
		B_1 int,B_2 int,B_3 int,B_4 int,B_5 int,B_6 int,B_7 int,B_8 int,B_9 int,B_10 int,B_11 int,
		B_12 int,B_13 int,B_14 int,B_15 int,B_16 int,B_17 int,B_18 int,B_19 int,B_20 int,B_21 int,
		B_22 int,B_23 int,B_24 int,B_25 int,B_26 int,B_27 int,B_28 int,B_29 int,B_30 int,
		Z_H int,J_O varchar(20),G_0 varchar(10),G_1 varchar(10),G_2 varchar(10),G_3 varchar(10),G_4 varchar(10),
		G_5 varchar(10),G_6 varchar(10),G_7 varchar(10),G_8 varchar(10),G_9 varchar(10),B_Q INT)

declare @cur cursor 
declare @Isuse varchar(20), @WinLotteryNumber varchar(100), @id int 

declare @B_1 int,@B_2 int,@B_3 int,@B_4 int,@B_5 int,@B_6 int,@B_7 int,@B_8 int,@B_9 int,@B_10 int,
		@B_11 int,@B_12 int,@B_13 int,@B_14 int,@B_15 int,@B_16 int,@B_17 int,@B_18 int,@B_19 int,@B_20 int,
		@B_21 int,@B_22 int,@B_23 int,@B_24 int,@B_25 int,@B_26 int,@B_27 int,@B_28 int,@B_29 int,@B_30 int
		
DECLARE @QW int,@BW int,@SW int,@W int,@Q INT,@B INT,@S INT,@Z_H INT ,@J_O VARCHAR(20),@B_Q INT
DECLARE @G_0 varchar(10),@G_1 varchar(10),@G_2 varchar(10),@G_3 varchar(10),@G_4 varchar(10),@G_5 varchar(10),
		@G_6 varchar(10),@G_7 varchar(10),@G_8 varchar(10),@G_9 varchar(10),@G INT



Create table #tb(id int,PlayNo varchar(20),WinLotteryNumber varchar(100))

		insert into #tb select Id,PlayNo,WinLotteryNumber from pm_plays with(nolock) where WinLotteryNumber <> '' and LotteryID = 13 order by [EndTime] asc

set @B_1 = 0 set @B_2 = 0 set @B_3 = 0 set @B_4 = 0 set @B_5 = 0 set @B_6 = 0  set @B_7 = 0 set @B_8 = 0 set @B_9 = 0
set @B_10 = 0 set @B_11 = 0 set @B_12 = 0 set @B_13 = 0 set @B_14 = 0 set @B_15 = 0 set @B_16 = 0  set @B_17 = 0 set @B_18 = 0 
set @B_19 = 0 set @B_20 = 0 set @B_21 = 0 set @B_22 = 0 set @B_23 = 0 set @B_24 = 0 set @B_25 = 0 set @B_26 = 0  set @B_27 = 0 
set @B_28 = 0 set @B_29 = 0 set @B_30 = 0 

set @cur = cursor FAST_FORWARD for select PlayNo,WinLotteryNumber from #tb 

open @cur

fetch next from @cur into @Isuse, @WinLotteryNumber

while @@fetch_status=0
begin

set @QW = Substring(@WinLotteryNumber,1,2) 
set @BW = Substring(@WinLotteryNumber,4,2) 
set @SW = Substring(@WinLotteryNumber,7,2)
set @W = Substring(@WinLotteryNumber,10,2) 
set @Q = Substring(@WinLotteryNumber,13,2)
set @B = Substring(@WinLotteryNumber,16,2) 
set @S = Substring(@WinLotteryNumber,19,2)
SET @G = Substring(@WinLotteryNumber,24,2)

DECLARE @J INT ,@O INT
SET @J=0 SET @O = 0 
SET @G_0 ='-1' SET @G_1 ='-1' SET @G_2 ='-1' SET @G_3 ='-1' SET @G_4 ='-1' SET @G_5 ='-1' SET @G_6 ='-1' SET @G_7 ='-1' SET @G_8 ='-1' SET @G_9 ='-1'

set @B_1 =@B_1 + 1 set @B_2 = @B_2 + 1 set @B_3 = @B_3 + 1 set @B_4 = @B_4 + 1 set @B_5 = @B_5 + 1 set @B_6 = @B_6 + 1
set @B_7 = @B_7 + 1 set @B_8 = @B_8 + 1 set @B_9 = @B_9 + 1 set @B_10 = @B_10 + 1 set @B_11 =@B_11 + 1 set @B_12 = @B_12 + 1 
set @B_13 = @B_13 + 1 set @B_14 = @B_14 + 1 set @B_15 = @B_15 + 1 set @B_16 = @B_16 + 1  set @B_17 = @B_17 + 1 set @B_18 = @B_18 + 1
set @B_19 = @B_19 + 1 set @B_20 = @B_20 + 1 set @B_21 =@B_21 + 1 set @B_22 = @B_22 + 1  set @B_23 = @B_23 + 1 set @B_24 = @B_24 + 1 
set @B_25 = @B_25 + 1 set @B_26 = @B_26 + 1  set @B_27 = @B_27 + 1 set @B_28 = @B_28 + 1 set @B_29 = @B_29 + 1 set @B_30 = @B_30 + 1 

IF(@QW=1 OR @BW = 1 OR @SW=1 OR @W=1 OR @Q=1 OR @B=1 OR @S=1 OR @G =1)
BEGIN
	SET @B_1 = 0
END

IF(@QW=2 OR @BW = 2 OR @SW=2 OR @W=2 OR @Q=2 OR @B=2 OR @S=2 OR @G =2)
BEGIN
	SET @B_2 = 0
END

IF(@QW=3 OR @BW = 3 OR @SW=3 OR @W=3 OR @Q=3 OR @B=3 OR @S=3 OR @G =3)
BEGIN
	SET @B_3 = 0
END

IF(@QW=4 OR @BW = 4 OR @SW=4 OR @W=4 OR @Q=4 OR @B=4 OR @S=4 OR @G =4)
BEGIN
	SET @B_4 = 0
END

IF(@QW=5 OR @BW = 5 OR @SW=5 OR @W=5 OR @Q=5 OR @B=5 OR @S=5 OR @G =5)
BEGIN
	SET @B_5 = 0
END

IF(@QW=6 OR @BW = 6 OR @SW=6 OR @W=6 OR @Q=6 OR @B=6 OR @S=6 OR @G =6)
BEGIN
	SET @B_6 = 0
END

IF(@QW=7 OR @BW = 7 OR @SW=7 OR @W=7 OR @Q=7 OR @B=7 OR @S= 7 OR @G =7)
BEGIN
	SET @B_7 = 0
END

IF(@QW=8 OR @BW = 8 OR @SW=8 OR @W=8 OR @Q=8 OR @B=8 OR @S=8 OR @G =8)
BEGIN
	SET @B_8 = 0
END

IF(@QW=9 OR @BW = 9 OR @SW=9 OR @W=9 OR @Q=9 OR @B=9 OR @S=9 OR @G =9)
BEGIN
	SET @B_9 = 0
END

IF(@QW=10 OR @BW = 10 OR @SW=10 OR @W=10 OR @Q=10 OR @B=10 OR @S=10 OR @G =10)
BEGIN
	SET @B_10 = 0
END

IF(@QW=11 OR @BW = 11 OR @SW=11 OR @W=11 OR @Q=11 OR @B=11 OR @S=11 OR @G =11)
BEGIN
	SET @B_11 = 0
END

IF(@QW=12 OR @BW = 12 OR @SW=12 OR @W=12 OR @Q=12 OR @B=12 OR @S=12 OR @G =12)
BEGIN
	SET @B_12 = 0
END

IF(@QW=13 OR @BW = 13 OR @SW=13 OR @W=13 OR @Q=13 OR @B=13 OR @S=13 OR @G =13)
BEGIN
	SET @B_13 = 0
END

IF(@QW=14 OR @BW = 14 OR @SW=14 OR @W=14 OR @Q=14 OR @B=14 OR @S=14 OR @G =14)
BEGIN
	SET @B_14 = 0
END

IF(@QW=15 OR @BW = 15 OR @SW=15 OR @W=15 OR @Q=15 OR @B=15 OR @S=15 OR @G =15)
BEGIN
	SET @B_15 = 0
END

IF(@QW=16 OR @BW = 16 OR @SW=16 OR @W=16 OR @Q=16 OR @B=16 OR @S=16 OR @G =16)
BEGIN
	SET @B_16 = 0
END

IF(@QW=17 OR @BW = 17 OR @SW=17 OR @W=17 OR @Q=17 OR @B=17 OR @S=17 OR @G =17)
BEGIN
	set @B_17 = 0
END

IF(@QW=18 OR @BW = 18 OR @SW=18 OR @W=18 OR @Q=18 OR @B=18 OR @S=18 OR @G =18)
BEGIN
	SET @B_18 = 0
END

IF(@QW=19 OR @BW = 19 OR @SW=19 OR @W=19 OR @Q=19 OR @B=19 OR @S=19 OR @G =19)
BEGIN
	SET @B_19 = 0
END

IF(@QW=20 OR @BW = 20 OR @SW=20 OR @W=20 OR @Q=20 OR @B=20 OR @S=20 OR @G =20)
BEGIN
	SET @B_20 = 0
END

IF(@QW=21 OR @BW = 21 OR @SW=21 OR @W=21 OR @Q=21 OR @B=21 OR @S=21 OR @G =21)
BEGIN
	SET @B_21 = 0
END

IF(@QW=22 OR @BW = 22 OR @SW=22 OR @W=22 OR @Q=22 OR @B=22 OR @S=22 OR @G =22)
BEGIN
	SET @B_22 = 0
END

IF(@QW=23 OR @BW = 23 OR @SW=23 OR @W=23 OR @Q=23 OR @B=23 OR @S=23 OR @G =23)
BEGIN
	SET @B_23 = 0
END

IF(@QW=24 OR @BW = 24 OR @SW=24 OR @W=24 OR @Q=24 OR @B=24 OR @S=24 OR @G =24)
BEGIN
	SET @B_24 = 0
END

IF(@QW=25 OR @BW = 25 OR @SW=25 OR @W=25 OR @Q=25 OR @B=25 OR @S=25 OR @G =25)
BEGIN
	SET @B_25 = 0
END

IF(@QW=26 OR @BW = 26 OR @SW=26 OR @W=26 OR @Q=26 OR @B=26 OR @S=26 OR @G =26)
BEGIN
	SET @B_26 = 0
END

IF(@QW=27 OR @BW = 27 OR @SW=27 OR @W=27 OR @Q=27 OR @B=27 OR @S=27 OR @G =27)
BEGIN
	SET @B_27 = 0
END

IF(@QW=28 OR @BW = 28 OR @SW=28 OR @W=28 OR @Q=28 OR @B=28 OR @S=28 OR @G =28)
BEGIN
	SET @B_28 = 0
END

IF(@QW=29 OR @BW = 29 OR @SW=29 OR @W=29 OR @Q=29 OR @B=29 OR @S=29 OR @G =29)
BEGIN
	SET @B_29 = 0
END

IF(@QW=30 OR @BW = 30 OR @SW=30 OR @W=30 OR @Q=30 OR @B=30 OR @S=30 OR @G =30)
BEGIN
	SET @B_30 = 0
END

set @Z_H = @QW + @BW + @SW + @W + @Q + @B +@S +@G

-------基偶统计

IF(@QW % 2 = 0)
BEGIN
	SET @O =@O + 1
END

IF(@BW % 2 = 0)
BEGIN
	SET @O =@O + 1
END

IF(@SW % 2 = 0)
BEGIN
	SET @O =@O + 1
END

IF(@W % 2 = 0)
BEGIN
	SET @O =@O + 1
END

IF(@Q % 2 = 0)
BEGIN
	SET @O =@O + 1
END

IF(@B % 2 = 0)
BEGIN
	SET @O =@O + 1
END

IF(@S % 2 = 0)
BEGIN
	SET @O =@O + 1
END

IF(@G % 2 = 0)
BEGIN
	SET @O =@O + 1
END

IF(@QW % 2 <> 0)
BEGIN
	SET @J =@J + 1
END

IF(@BW % 2 <> 0)
BEGIN
	SET @J =@J + 1
END

IF(@SW % 2 <> 0)
BEGIN
	SET @J =@J + 1
END

IF(@W % 2 <> 0)
BEGIN
	SET @J =@J + 1
END

IF(@Q % 2 <> 0)
BEGIN
	SET @J =@J + 1
END

IF(@B % 2 <> 0)
BEGIN
	SET @J =@J + 1
END

IF(@S % 2 <> 0)
BEGIN
	SET @J =@J + 1
END

IF(@G % 2 <> 0)
BEGIN
	SET @J =@J + 1
END
SET @J_O = (rtrim(ltrim(STR(@J)))) +' : '+(rtrim(ltrim(STR(@O))))

---个位分布---

DECLARE @G_W_1 VARCHAR(2),@G_W_2 VARCHAR(2),@G_W_3 VARCHAR(2),@G_W_4 VARCHAR(2),
		@G_W_5 VARCHAR(2),@G_W_6 VARCHAR(2),@G_W_7 VARCHAR(2),@G_W_8 VARCHAR(2)

set @G_W_1 = Substring(@WinLotteryNumber,2,1) 
set @G_W_2 = Substring(@WinLotteryNumber,5,1) 
set @G_W_3 = Substring(@WinLotteryNumber,8,1)
set @G_W_4 = Substring(@WinLotteryNumber,11,1) 
set @G_W_5 = Substring(@WinLotteryNumber,14,1)
set @G_W_6 = Substring(@WinLotteryNumber,17,1) 
set @G_W_7 = Substring(@WinLotteryNumber,20,1)
set @G_W_8 = Substring(@WinLotteryNumber,25,1)

IF(@G_W_1 ='0' OR @G_W_2 ='0' OR @G_W_3 ='0' OR @G_W_4 ='0' OR @G_W_5 ='0' OR @G_W_6 ='0' OR @G_W_7 ='0' OR @G_W_8='0' )
BEGIN
	SET @G_0 = 'Blue|0'
	IF((@G_W_1='0' AND @G_W_2='0') OR(@G_W_1='0' AND @G_W_3='0') OR (@G_W_1='0' AND @G_W_4='0') OR (@G_W_1='0' AND @G_W_5='0')OR (@G_W_1='0' AND @G_W_6='0') OR (@G_W_1='0' AND @G_W_7='0')OR (@G_W_1='0' AND @G_W_8='0')
		OR (@G_W_2='0' AND @G_W_3='0') OR(@G_W_2='0' AND @G_W_4='0') OR(@G_W_2='0' AND @G_W_5='0')OR (@G_W_2='0' AND @G_W_6='0') OR(@G_W_2='0' AND @G_W_7='0')OR (@G_W_2='0' AND @G_W_8='0')OR (@G_W_3='0' AND @G_W_8='0')
		OR(@G_W_3='0' AND @G_W_4='0') OR(@G_W_3='0' AND @G_W_5='0')OR(@G_W_3='0' AND @G_W_6='0')OR(@G_W_3='0' AND @G_W_7='0')OR (@G_W_4='0' AND @G_W_8='0')OR (@G_W_5='0' AND @G_W_8='0')OR (@G_W_6='0' AND @G_W_8='0')
		OR(@G_W_4='0' AND @G_W_5='0') OR (@G_W_4='0' AND @G_W_6='0') OR(@G_W_4='0' AND @G_W_7='0') OR(@G_W_5='0' AND @G_W_6='0')OR(@G_W_5='0' AND @G_W_7='0') OR(@G_W_6='0' AND @G_W_7='0')OR (@G_W_8='0' AND @G_W_7='0'))
		BEGIN
			SET @G_0 ='Red|0'
		END
END

IF(@G_W_1 ='1' OR @G_W_2 ='1' OR @G_W_3 ='1' OR @G_W_4 ='1' OR @G_W_5 ='1' OR @G_W_6 ='1' OR @G_W_7 ='1' OR @G_W_8='1')
BEGIN
	SET @G_1 = 'Blue|1'
	IF((@G_W_1='1' AND @G_W_2='1') OR(@G_W_1='1' AND @G_W_3='1') OR (@G_W_1='1' AND @G_W_4='1') OR (@G_W_1='1' AND @G_W_5='1')OR (@G_W_1='1' AND @G_W_6='1') OR (@G_W_1='1' AND @G_W_7='1')OR (@G_W_1='1' AND @G_W_8='1')
		OR (@G_W_2='1' AND @G_W_3='1') OR(@G_W_2='1' AND @G_W_4='1') OR(@G_W_2='1' AND @G_W_5='1')OR (@G_W_2='1' AND @G_W_6='1') OR(@G_W_2='1' AND @G_W_7='1')OR (@G_W_2='1' AND @G_W_8='1')OR (@G_W_3='1' AND @G_W_8='1')
		OR(@G_W_3='1' AND @G_W_4='1') OR(@G_W_3='1' AND @G_W_5='1')OR(@G_W_3='1' AND @G_W_6='1')OR(@G_W_3='1' AND @G_W_7='1')OR (@G_W_4='1' AND @G_W_8='1')OR (@G_W_5='1' AND @G_W_8='1')OR (@G_W_6='1' AND @G_W_8='1')
		OR(@G_W_4='1' AND @G_W_5='1') OR (@G_W_4='1' AND @G_W_6='1') OR(@G_W_4='1' AND @G_W_7='1') OR(@G_W_5='1' AND @G_W_6='1')OR(@G_W_5='1' AND @G_W_7='1') OR(@G_W_6='1' AND @G_W_7='1')OR (@G_W_8='1' AND @G_W_7='1'))
		BEGIN
			SET @G_1 ='Red|1'
		END
END

IF(@G_W_1 ='2' OR @G_W_2 ='2' OR @G_W_3 ='2' OR @G_W_4 ='2' OR @G_W_5 ='2' OR @G_W_6 ='2' OR @G_W_7 ='2' OR @G_W_8='2' )
BEGIN
	SET @G_2 = 'Blue|2'
	IF((@G_W_1='2' AND @G_W_2='2') OR(@G_W_1='2' AND @G_W_3='2') OR (@G_W_1='2' AND @G_W_4='2') OR (@G_W_1='2' AND @G_W_5='2')OR (@G_W_1='2' AND @G_W_6='2') OR (@G_W_1='2' AND @G_W_7='2')OR (@G_W_1='2' AND @G_W_8='2')
		OR (@G_W_2='2' AND @G_W_3='2') OR(@G_W_2='2' AND @G_W_4='2') OR(@G_W_2='2' AND @G_W_5='2')OR (@G_W_2='2' AND @G_W_6='2') OR(@G_W_2='2' AND @G_W_7='2')OR (@G_W_2='2' AND @G_W_8='2')OR (@G_W_3='2' AND @G_W_8='2')
		OR(@G_W_3='2' AND @G_W_4='2') OR(@G_W_3='2' AND @G_W_5='2')OR(@G_W_3='2' AND @G_W_6='2')OR(@G_W_3='2' AND @G_W_7='2')OR (@G_W_4='2' AND @G_W_8='2')OR (@G_W_5='2' AND @G_W_8='2')OR (@G_W_6='2' AND @G_W_8='2')
		OR(@G_W_4='2' AND @G_W_5='2') OR (@G_W_4='2' AND @G_W_6='2') OR(@G_W_4='2' AND @G_W_7='2') OR(@G_W_5='2' AND @G_W_6='2')OR(@G_W_5='2' AND @G_W_7='2') OR(@G_W_6='2' AND @G_W_7='2')OR (@G_W_8='2' AND @G_W_7='2'))
		BEGIN
			SET @G_2 ='Red|2'
		END
END

IF(@G_W_1 ='3' OR @G_W_2 ='3' OR @G_W_3 ='3' OR @G_W_4 ='3' OR @G_W_5 ='3' OR @G_W_6 ='3' OR @G_W_7 ='3' OR @G_W_8='3' )
BEGIN
	SET @G_3 = 'Blue|3'
	IF((@G_W_1='3' AND @G_W_2='3') OR(@G_W_1='3' AND @G_W_3='3') OR (@G_W_1='3' AND @G_W_4='3') OR (@G_W_1='3' AND @G_W_5='3')OR (@G_W_1='3' AND @G_W_6='3') OR (@G_W_1='3' AND @G_W_7='3')OR (@G_W_1='3' AND @G_W_8='3')
		OR (@G_W_2='3' AND @G_W_3='3') OR(@G_W_2='3' AND @G_W_4='3') OR(@G_W_2='3' AND @G_W_5='3')OR (@G_W_2='3' AND @G_W_6='3') OR(@G_W_2='3' AND @G_W_7='3')OR (@G_W_2='3' AND @G_W_8='3')OR (@G_W_3='3' AND @G_W_8='3')
		OR(@G_W_3='3' AND @G_W_4='3') OR(@G_W_3='3' AND @G_W_5='3')OR(@G_W_3='3' AND @G_W_6='3')OR(@G_W_3='3' AND @G_W_7='3')OR (@G_W_4='3' AND @G_W_8='3')OR (@G_W_5='3' AND @G_W_8='3')OR (@G_W_6='3' AND @G_W_8='3')
		OR(@G_W_4='3' AND @G_W_5='3') OR (@G_W_4='3' AND @G_W_6='3') OR(@G_W_4='3' AND @G_W_7='3') OR(@G_W_5='3' AND @G_W_6='3')OR(@G_W_5='3' AND @G_W_7='3') OR(@G_W_6='3' AND @G_W_7='3')OR (@G_W_8='3' AND @G_W_7='3'))
		BEGIN
			SET @G_3 ='Red|3'
		END
END

IF(@G_W_1 ='4' OR @G_W_2 ='4' OR @G_W_3 ='4' OR @G_W_4 ='4' OR @G_W_5 ='4' OR @G_W_6 ='4' OR @G_W_7 ='4' OR @G_W_8='4')
BEGIN
	SET @G_4 = 'Blue|4'
	IF((@G_W_1='4' AND @G_W_2='4') OR(@G_W_1='4' AND @G_W_3='4') OR (@G_W_1='4' AND @G_W_4='4') OR (@G_W_1='4' AND @G_W_5='4')OR (@G_W_1='4' AND @G_W_6='4') OR (@G_W_1='4' AND @G_W_7='4')OR (@G_W_1='4' AND @G_W_8='4')
		OR (@G_W_2='4' AND @G_W_3='4') OR(@G_W_2='4' AND @G_W_4='4') OR(@G_W_2='4' AND @G_W_5='4')OR (@G_W_2='4' AND @G_W_6='4') OR(@G_W_2='4' AND @G_W_7='4')OR(@G_W_2='4' AND @G_W_8='4')OR(@G_W_3='4' AND @G_W_8='4')
		OR(@G_W_3='4' AND @G_W_4='4') OR(@G_W_3='4' AND @G_W_5='4')OR(@G_W_3='4' AND @G_W_6='4')OR(@G_W_3='4' AND @G_W_7='4')OR(@G_W_4='4' AND @G_W_8='4')OR(@G_W_5='4' AND @G_W_8='4')OR(@G_W_6='4' AND @G_W_8='4')
		OR(@G_W_4='4' AND @G_W_5='4') OR (@G_W_4='4' AND @G_W_6='4') OR(@G_W_4='4' AND @G_W_7='4') OR(@G_W_5='4' AND @G_W_6='4')OR(@G_W_5='4' AND @G_W_7='4') OR(@G_W_6='4' AND @G_W_7='4')OR(@G_W_8='4' AND @G_W_7='4'))
		BEGIN
			SET @G_4 ='Red|4'
		END
END

IF(@G_W_1 ='5' OR @G_W_2 ='5' OR @G_W_3 ='5' OR @G_W_4 ='5' OR @G_W_5 ='5' OR @G_W_6 ='5' OR @G_W_7 ='5' OR @G_W_8='5' )
BEGIN
	SET @G_5 = 'Blue|5'
	IF((@G_W_1='5' AND @G_W_2='5') OR(@G_W_1='5' AND @G_W_3='5') OR (@G_W_1='5' AND @G_W_4='5') OR (@G_W_1='5' AND @G_W_5='5')OR (@G_W_1='5' AND @G_W_6='5') OR (@G_W_1='5' AND @G_W_7='5')OR (@G_W_1='5' AND @G_W_8='5')
		OR (@G_W_2='5' AND @G_W_3='5') OR(@G_W_2='5' AND @G_W_4='5') OR(@G_W_2='5' AND @G_W_5='5')OR (@G_W_2='5' AND @G_W_6='5') OR(@G_W_2='5' AND @G_W_7='5') OR(@G_W_2='5' AND @G_W_8='5') OR(@G_W_3='5' AND @G_W_8='5')
		OR(@G_W_3='5' AND @G_W_4='5') OR(@G_W_3='5' AND @G_W_5='5')OR(@G_W_3='5' AND @G_W_6='5')OR(@G_W_3='5' AND @G_W_7='5') OR(@G_W_4='5' AND @G_W_8='5') OR(@G_W_5='5' AND @G_W_8='5') OR(@G_W_6='5' AND @G_W_8='5')
		OR(@G_W_4='5' AND @G_W_5='5') OR (@G_W_4='5' AND @G_W_6='5') OR(@G_W_4='5' AND @G_W_7='5') OR(@G_W_5='5' AND @G_W_6='5')OR(@G_W_5='5' AND @G_W_7='5') OR(@G_W_6='5' AND @G_W_7='5')  OR(@G_W_8='5' AND @G_W_7='5'))
		BEGIN
			SET @G_5 ='Red|5'
		END
END

IF(@G_W_1 ='6' OR @G_W_2 ='6' OR @G_W_3 ='6' OR @G_W_4 ='6' OR @G_W_5 ='6' OR @G_W_6 ='6' OR @G_W_7 ='6' OR @G_W_8='6')
BEGIN
	SET @G_6 = 'Blue|6'
	IF((@G_W_1='6' AND @G_W_2='6') OR(@G_W_1='6' AND @G_W_3='6') OR (@G_W_1='6' AND @G_W_4='6') OR (@G_W_1='6' AND @G_W_5='6')OR (@G_W_1='6' AND @G_W_6='6') OR (@G_W_1='6' AND @G_W_7='6')OR (@G_W_1='6' AND @G_W_8='6')
		OR (@G_W_2='6' AND @G_W_3='6') OR(@G_W_2='6' AND @G_W_4='6') OR(@G_W_2='6' AND @G_W_5='6')OR (@G_W_2='6' AND @G_W_6='6') OR(@G_W_2='6' AND @G_W_7='6')OR(@G_W_2='6' AND @G_W_8='6')OR(@G_W_3='6' AND @G_W_8='6')
		OR(@G_W_3='6' AND @G_W_4='6') OR(@G_W_3='6' AND @G_W_5='6')OR(@G_W_3='6' AND @G_W_6='6')OR(@G_W_3='6' AND @G_W_7='6')OR(@G_W_4='6' AND @G_W_8='6')OR(@G_W_5='6' AND @G_W_8='6')OR(@G_W_6='6' AND @G_W_8='6')
		OR(@G_W_4='6' AND @G_W_5='6') OR (@G_W_4='6' AND @G_W_6='6') OR(@G_W_4='6' AND @G_W_7='6') OR(@G_W_5='6' AND @G_W_6='6')OR(@G_W_5='6' AND @G_W_7='6') OR(@G_W_6='6' AND @G_W_7='6') OR(@G_W_8='6' AND @G_W_7='6'))
		BEGIN
			SET @G_6 ='Red|6'
		END
END

IF(@G_W_1 ='7' OR @G_W_2 ='7' OR @G_W_3 ='7' OR @G_W_4 ='7' OR @G_W_5 ='7' OR @G_W_6 ='7' OR @G_W_7 ='7' OR @G_W_8='7' )
BEGIN
	SET @G_7 = 'Blue|7'
	IF((@G_W_1='7' AND @G_W_2='7') OR(@G_W_1='7' AND @G_W_3='7') OR (@G_W_1='7' AND @G_W_4='7') OR (@G_W_1='7' AND @G_W_5='7')OR (@G_W_1='7' AND @G_W_6='7') OR (@G_W_1='7' AND @G_W_7='7')OR (@G_W_1='7' AND @G_W_8='7')
		OR (@G_W_2='7' AND @G_W_3='7') OR(@G_W_2='7' AND @G_W_4='7') OR(@G_W_2='7' AND @G_W_5='7')OR (@G_W_2='7' AND @G_W_6='7') OR(@G_W_2='7' AND @G_W_7='7')OR(@G_W_2='7' AND @G_W_8='7')
		OR(@G_W_3='7' AND @G_W_4='7') OR(@G_W_3='7' AND @G_W_5='7')OR(@G_W_3='7' AND @G_W_6='7')OR(@G_W_3='7' AND @G_W_7='7')OR(@G_W_3='7' AND @G_W_8='7')OR(@G_W_4='7' AND @G_W_8='7')OR(@G_W_5='7' AND @G_W_8='7')
		OR(@G_W_4='7' AND @G_W_5='7') OR (@G_W_4='7' AND @G_W_6='7') OR(@G_W_4='7' AND @G_W_7='7') OR(@G_W_5='7' AND @G_W_6='7')OR(@G_W_5='7' AND @G_W_7='7') OR(@G_W_6='7' AND @G_W_7='7')OR(@G_W_6='7' AND @G_W_8='7')OR(@G_W_8='7' AND @G_W_7='7'))
		BEGIN
			SET @G_7 ='Red|7'
		END
END

IF(@G_W_1 ='8' OR @G_W_2 ='8' OR @G_W_3 ='8' OR @G_W_4 ='8' OR @G_W_5 ='8' OR @G_W_6 ='8' OR @G_W_7 ='8' OR @G_W_8='8')
BEGIN
	SET @G_8 = 'Blue|8'
	IF((@G_W_1='8' AND @G_W_2='8') OR(@G_W_1='8' AND @G_W_3='8') OR (@G_W_1='8' AND @G_W_4='8') OR (@G_W_1='8' AND @G_W_5='8')OR (@G_W_1='8' AND @G_W_6='8') OR (@G_W_1='8' AND @G_W_7='8')OR (@G_W_1='8' AND @G_W_8='8')
		OR (@G_W_2='8' AND @G_W_3='8') OR(@G_W_2='8' AND @G_W_4='8') OR(@G_W_2='8' AND @G_W_5='8')OR (@G_W_2='8' AND @G_W_6='8') OR(@G_W_2='8' AND @G_W_7='8')OR(@G_W_2='8' AND @G_W_8='8')
		OR(@G_W_3='8' AND @G_W_4='8') OR(@G_W_3='8' AND @G_W_5='8')OR(@G_W_3='8' AND @G_W_6='8')OR(@G_W_3='8' AND @G_W_7='8')OR(@G_W_3='8' AND @G_W_8='8')
		OR(@G_W_4='8' AND @G_W_5='8') OR (@G_W_4='8' AND @G_W_6='8') OR(@G_W_4='8' AND @G_W_7='8') OR(@G_W_4='8' AND @G_W_8='8') OR(@G_W_5='8' AND @G_W_6='8')OR(@G_W_5='8' AND @G_W_7='8')OR(@G_W_5='8' AND @G_W_8='8') OR(@G_W_6='8' AND @G_W_7='8')OR(@G_W_6='8' AND @G_W_8='8') OR(@G_W_8='8' AND @G_W_7='8'))
		BEGIN
			SET @G_8 ='Red|8'
		END
END

IF(@G_W_1 ='9' OR @G_W_2 ='9' OR @G_W_3 ='9' OR @G_W_4 ='9' OR @G_W_5 ='9' OR @G_W_6 ='9' OR @G_W_7 ='9' OR @G_W_8='9')
BEGIN
	SET @G_9 = 'Blue|9'
	IF((@G_W_1='9' AND @G_W_2='9') OR(@G_W_1='9' AND @G_W_3='9') OR (@G_W_1='9' AND @G_W_4='9') OR (@G_W_1='9' AND @G_W_5='9')OR (@G_W_1='9' AND @G_W_6='9') OR (@G_W_1='9' AND @G_W_7='9')OR (@G_W_1='9' AND @G_W_8='9')
		OR (@G_W_2='9' AND @G_W_3='9') OR(@G_W_2='9' AND @G_W_4='9') OR(@G_W_2='9' AND @G_W_5='9')OR (@G_W_2='9' AND @G_W_6='9') OR(@G_W_2='9' AND @G_W_7='9') OR(@G_W_2='9' AND @G_W_8='9')
		OR(@G_W_3='9' AND @G_W_4='9') OR(@G_W_3='9' AND @G_W_5='9')OR(@G_W_3='9' AND @G_W_6='9')OR(@G_W_3='9' AND @G_W_7='9')OR(@G_W_3='9' AND @G_W_8='9')
		OR(@G_W_4='9' AND @G_W_5='9') OR (@G_W_4='9' AND @G_W_6='9') OR(@G_W_4='9' AND @G_W_7='9') OR(@G_W_4='9' AND @G_W_8='9')  OR(@G_W_5='9' AND @G_W_6='9')OR(@G_W_5='9' AND @G_W_7='9') OR(@G_W_5='9' AND @G_W_8='9') OR(@G_W_6='9' AND @G_W_7='9')OR(@G_W_6='9' AND @G_W_8='9') OR(@G_W_8='9' AND @G_W_7='9'))
		BEGIN
			SET @G_9 ='Red|9'
		END
END

SET @B_Q = Substring(@WinLotteryNumber,24,2)
insert into #LotteryNumberList7CL values (@Isuse,@B_1,@B_2 ,@B_3 ,@B_4 ,@B_5,@B_6 ,
		@B_7 ,@B_8,@B_9,@B_10,@B_11,@B_12 ,@B_13 ,@B_14 ,@B_15,@B_16 ,@B_17 ,@B_18,@B_19,@B_20,@B_21,@B_22, 
		@B_23 ,@B_24 ,@B_25,@B_26 ,@B_27 ,@B_28,@B_29,@B_30,@Z_H,@J_O,@G_0,@G_1,@G_2,@G_3,@G_4,@G_5,@G_6,@G_7,@G_8,@G_9,@B_Q)
	

fetch next from @cur into @Isuse, @WinLotteryNumber

end

close @cur

select * from #LotteryNumberList7CL



set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON

GO


exec P_TrendChart_7CL_HMFB